package com.itheima.web;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.CheckItem;
import com.itheima.pojo.Permission;
import com.itheima.service.PermissionService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @description:
 * @author: tantan
 * @date: 2020/4/19-15:03
 * @Version: 1.0.0
 */
@RestController
@RequestMapping("/permission")
public class PermissionController {

    @Reference
    PermissionService permissionService;

    @RequestMapping("/findAll")
    public Result findAll(){
        List<Permission> permissionList = permissionService.findAll();
        return Result.OK("",permissionList);
    }

    @RequestMapping("/add")
    public Result add(@RequestBody CheckItem checkItem){//由于前端传的是json我SB了没有加@RequestBody
        permissionService.add(checkItem);
        return new Result(true, MessageConstant.ADD_CHECKITEM_SUCCESS);
    }

  /*  @RequestMapping("/findAll")
    public Result findAll(){
        List<CheckItem> checkItems = checkItemService.findAll();
        return Result.OK("",checkItems);
    }*/

    @RequestMapping("/edit")
    public Result edit(@RequestBody Permission Permission){
        permissionService.edit(Permission);
        return Result.OK("");
    }

    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        return permissionService.findPage(queryPageBean);
    }

    @RequestMapping("/delete")
//    @PreAuthorize("hasAuthority('CHECKITEM_DELETE')")
    /*  @PreAuthorize("hasAnyAuthority('CHECKITEM_DELETE','CHECKITEM_ADD')")*/
    public Result delete(Integer id){
        permissionService.delete(id);
        return new Result(true,"删除成功");
    }

    @RequestMapping("/findById")
    public Result findById(Integer id){
        Permission Permission =  permissionService.findById(id);
        return new Result(true,"",Permission);//查询了一定要返回
    }
}
